package com.simple.gateway.common.util;

import com.simple.gateway.common.authorization.JwtUtil;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 项目: simple-gateway-core
 *
 * 功能描述:
 *
 * @author: WuChengXing
 *
 * @create: 2023-08-31 14:46
 **/
public class TokenGenerateUtil {

    private static final Long DEFAULT_TTL_MILLIS = 7 * 24 * 60 * 60 * 1000L;

    public static String generateToken(String userKey, Long ttlMillis) {

        if (Objects.isNull(ttlMillis)) {
            ttlMillis = DEFAULT_TTL_MILLIS;
        }
        Map<String, Object> claims = new HashMap<>(2);
        claims.put("key", userKey);
        return JwtUtil.encode(userKey, ttlMillis, claims);
    }
}
